#ifndef _Connection
#define _Connection

#undef UNICODE
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>

// Need to link with Ws2_32.lib
#pragma comment (lib, "Ws2_32.lib")
// #pragma comment (lib, "Mswsock.lib")
#include "ParamManager.h"
#include "BufferManager.h"


namespace tlnet {

class Connection {

public:
	// settings
	ParamManager settings;
	// incoming data buffer
	BufferManager *bm;
	// network socket
	SOCKET socket;

	// insure thread-safe
	HANDLE mutex;
	HANDLE hReady;
	// thread related to the incoming data
	uintptr_t thread;

	// for link-list purposes
	Connection *prev, *next;

	// Constructor
	Connection(HANDLE /*mutex*/, HANDLE /*isReady*/);
	// Deconstructor
	~Connection();

	bool set(char* /*data*/, char* /*value*/);
	char* get(char* /*data*/);
	bool del(char* /*data*/);

	// returns a pointer to the current available string,
	// or NULL if none is available
	char* getData();

	// removes current available string
	void pop();

	// keeps the current available string saved & available at next eol
	void push();

	// write data to the socket
	bool write(char* /*data*/);
	bool write(char* /*data*/, int count);
};

}

#endif // _Connection